-
-
Notifications
You must be signed in to change notification settings - Fork 42
ZA | 25-SDC-July | Luke Manyamazi | Sprint 3 | Implement Shell Tools Exercises #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
ZA | 25-SDC-July | Luke Manyamazi | Sprint 3 | Implement Shell Tools Exercises #132
Conversation
LonMcGregor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work on this, I've left some comments for where you could start to improve more.
For your questions, yes, it looks like you're handling defaults for wc fine. I think you are handling output fine.
If you are thinking of handling more edge cases, think about how people might use these commands - what sort of arguments might get passed to your code?
implement-shell-tools/cat/cat.mjs
Outdated
| const lines = content.split('\n'); | ||
|
|
||
| for (const line of lines) { | ||
| const shouldNumber = (numberAllLines && !numNotBlank) || (numNotBlank && line.trim() !== ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are not numbering non-blank lines when -b is used. Can you see why that is?
implement-shell-tools/ls/ls.mjs
Outdated
| .name("ls") | ||
| .description("Lists the files in a directory") | ||
| .option("-1, --one", "One per line") | ||
| .option("-a", "Include files starting with dot") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You offer -a as an option, but is this ever used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throughout this file there is quite a lot of duplication. Can you think of how you might reduce this?
- cat.mjs: - Fixed -b option to number only non-blank lines. - Unified line number padding to avoid repetition. - Added error handling for directories and missing files. - ls.mjs: - Correctly implemented -a option to include hidden files. - Validates single directory argument. - Sorted output and handled one-column listing. - wc.mjs: - Centralized line, word, and character counting in countFile(). - Defaults to counting all metrics if no options are given. - Added support for multiple files with totals. - Improved error handling for missing files and directories. Overall: - Removed duplication, clarified logic, and improved alignment with standard Unix behavior.
|
Hi @LonMcGregor, Thanks for your feedback! Here’s a summary of the changes and improvements made to cat.mjs, ls.mjs, and wc.mjs: 1️⃣ cat.mjs Fixed numbering logic for -b (number non-blank lines). Previously, non-blank lines weren’t consistently numbered. 2️⃣ ls.mjs 3️⃣ wc.mjs |
LonMcGregor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making these changes. cat and ls look good now. I still notice some duplication in the wc file however.
Have a look at the last 2 blocks of code. They're both doing the same thing: Check options, push to an array,add padding, then print out. Is there a way you could abstract that code a bit?
… counts into `formatCounts()` helper - Precompute active count options in `activeCounts` to remove repeated ternaries - Simplify per-file and total output logic for readability and maintainability
|
Yes, I can abstract that repetition into a helper function, e.g. formatCounts(result, options) that returns the formatted count string for a given result object. Check my implementation. |
LonMcGregor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! You're finished with this task now
Learners, PR Template
Self checklist
Changelist
This PR includes implementations of basic Unix-like command-line tools in Node.js:
ls: Lists files in a directory.
cat: Reads and prints the contents of one or more files.
wc: Counts lines, words, and characters in one or more files, with support for flags (-l, -w, -c).
Each command was tested to match expected output behavior for the given use cases.
Questions